<template>
  <div 
    class="avatar" 
    :class="[size]"
    :title="user.username"
  >
    <img 
      v-if="user.profile?.avatarUrl" 
      :src="user.profile.avatarUrl" 
      :alt="user.username"
    />
    <span v-else>{{ initials }}</span>
  </div>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  user: {
    type: Object,
    required: true
  },
  size: {
    type: String,
    default: 'medium',
    validator: (value) => ['small', 'medium', 'large'].includes(value)
  }
});

const initials = computed(() => {
  return props.user.username
    .split(' ')
    .map(word => word[0])
    .join('')
    .toUpperCase()
    .slice(0, 2);
});
</script>

<style scoped>
.avatar {
  border-radius: 50%;
  background-color: #DFE1E6;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #172B4D;
  font-weight: bold;
}

.small {
  width: 24px;
  height: 24px;
  font-size: 12px;
}

.medium {
  width: 32px;
  height: 32px;
  font-size: 14px;
}

.large {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
</style> 